Skip to content

Conversation

marmoure
Copy link
Contributor

@marmoure marmoure commented Jan 3, 2023

Closes #200 .
This PR uses @wolfgangmm #227 for the URL Rewriting and all the fixes in that Pr.
It removes outdated parts, rename all xql to xq.

This open source contribution to the documentation project was commissioned by the Office of the Historian, U.S. Department of State, https://history.state.gov/.

@marmoure marmoure changed the title URL Rewriting intro URL Rewriting Jan 16, 2023
@joewiz
Copy link
Member

joewiz commented Jan 17, 2023

Thank you, @marmoure and @adamretter.

With the stated goal of #200 being a thoroughly updated article that is approachable and presents the key information that users need to know about the URL Rewriting facility (a "major job", as Erik characterized it), I'd suggest that more revision is necessary here. Wolfgang's draft revised introduction is a good start, but the body of the article needs to be reviewed to meet the stated goals of #200. As a starting point, I would suggest reading the relevant sections from the eXist book (pp. 194-207), since it comprehensively describes the URL rewriting facility. Make a note of what's covered there - for example, permissions considerations - and be sure all information is addressed here and introduced coherently. As Erik recommended, "postpone stuff about servlets and MVC patterns and all stuff you don't need for the basic understanding to sections at the end." The article should address the typical user looking to exert full control over their URLs and tell them what they need to know to do so.

Also, please be sure the CI passes.

@yamahito
Copy link
Contributor

@joewiz I've spent some time reworking the article, restructuring in some places, adding examples, and aiming for a more concise wording. How does it look?

@line-o
Copy link
Member

line-o commented Jan 31, 2023

@yamahito much clearer now 👍🏼

<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" schematypens="http://relaxng.org/ns/structure/1.0"?><?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?><article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
<info>
<title>URL Rewriting</title>
<date>2Q19</date>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Author Reference, this should be updated to February 2023 or 1Q23.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; will fix that.

</orderedlist>
<sect2 xml:id="eg1">
<title>Example I: A Simple Implementation</title>
<para>Consider the document you are currently reading; a direct URL pointing to the source data might be <code>/exist/apps/doc/data/urlrewrite.xml</code>. But accessing this URI would only show a user the raw XML: instead users should get a properly formatted HTML version of the text, accessible through a simple URL like <code>/exist/apps/doc/urlrewrite</code>.</para>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the direct source URL to the source XML for this article would be /exist/rest/db/apps/doc/data/urlrewrite.xml.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reword this, since the URLs do not really point to this exact document (which is at /exist/apps/doc/data/urlrewrite/urlrewrite.xml - I think bringing the rest interface into it muddies the waters even further). I considered changing all of the URLs to match the actual docbook article, but I think the important thing is that they are consistent.

</term>
</orderedlist>
<sect2 xml:id="eg1">
<title>Example I: A Simple Implementation</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next example is "Example 2", so perhaps best to stick with Arabic numerals -> "Example 1".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added Example C fixed.

declare variable $exist:root external;

<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/transform.xql">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text refers to this XQuery as transform.xq - i.e., without the l.

<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="data/{$exist:resource}.xml"/>
<view>
<forward url="{$exist:controller}/modules/transform.xql"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text refers to this XQuery as transform.xq - i.e., without the l.

<para><literal>controller.xq</literal> is invoked for all URL paths targeting the collection in which it resides. It has access to a number of <xref linkend="variables"/> pre-filled with details about the request, including <literal>$exist:resource</literal>, containing the name of the resource (without path components) the request tries to access; also the <literal>$exist:controller</literal> variable which points to the collection the <literal>controller.xq</literal> is located in.</para>
<para>For example, one may want to direct all requests to <literal>/exist/apps/doc/{resource}</literal> to an XQuery, <literal>transform.xq</literal>, which is responsible for converting the XML content into HTML:</para>
<programlisting language="xquery" xlink:href="listings/listing-1.txt"/>
<para>This example controller returns a simple <tag>dispatch</tag> fragment which will be passed back to the URL rewriting framework. The <tag>forward</tag> element instructs the framework to call the URL <literal>modules/transform.xq</literal> relative to the collection in which the controller resides. It adds a request parameter, named <literal>doc</literal>, which translates the requested resource into an actual document path to be transformed.</para>
Copy link
Member

@joewiz joewiz Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding another sentence to the end of this paragraph:

The receiving query could access this parameter using request:get-parameter("doc", ()) in order to retrieve the requested article.

<para><literal>controller.xq</literal> is invoked for all URL paths targeting the collection in which it resides. It has access to a number of <xref linkend="variables"/> pre-filled with details about the request, including <literal>$exist:resource</literal>, containing the name of the resource (without path components) the request tries to access; also the <literal>$exist:controller</literal> variable which points to the collection the <literal>controller.xq</literal> is located in.</para>
<para>For example, one may want to direct all requests to <literal>/exist/apps/doc/{resource}</literal> to an XQuery, <literal>transform.xq</literal>, which is responsible for converting the XML content into HTML:</para>
<programlisting language="xquery" xlink:href="listings/listing-1.txt"/>
<para>This example controller returns a simple <tag>dispatch</tag> fragment which will be passed back to the URL rewriting framework. The <tag>forward</tag> element instructs the framework to call the URL <literal>modules/transform.xq</literal> relative to the collection in which the controller resides. It adds a request parameter, named <literal>doc</literal>, which translates the requested resource into an actual document path to be transformed.</para>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's totally accurate to say that the request parameter named doc "translates the requested resource into an actual document path". Instead, doc contains the name of the resource sans path components (e.g., urlrewrite) plus the file extension of the actual document stored in the database (e.g., urlrewrite.xml).

@yamahito
Copy link
Contributor

yamahito commented Feb 9, 2023

@joewiz I've attempted to address your feedback points. Thanks!

wolfgangmm and others added 16 commits March 19, 2023 19:06
- `xref/@linkend` already correctly handles cross references using the title of the resource, but `link` can also use `@linkend` where internal links are desirable with different labels.
- Refactored for best practice push XSLT paradigm.
- Built on existing work by Wolfgang and others
- removed extra verbal padding for more concise document
- Re-ordered some of the more complex topics to the end of the document
- Re-factored headings for easier navigation from sidebar (e.g. controller XML model) and better internal linking
- Reviewed the eXist O'Reilly book content to ensure documentation parity
- Added some examples
- missing @xml:id on `sect2`
- replace `tag` within `link` with `literal`
- corrected query names to `.xq` from `xql` in examples
- Updated date
- renumbered examples for consistency
- Reworded Example 1
@adamretter
Copy link
Contributor

@joewiz I have fixed the date and cleaned up the commit history. This should be ready for you to merge now if you are happy to do so.

@joewiz
Copy link
Member

joewiz commented Mar 19, 2023

@adamretter Would you please pull in my evolvedbinary#1, so that this PR incorporates that review?

@adamretter
Copy link
Contributor

@joewiz Sorry, I wasn't aware of your evolvedbinary#1.
I think it''s best not to send PRs to our fork please.

I just took a look at that PR and there seems to be merge conflicts. Can I suggest that this gets merged first, and then you could reopen your PR against this repo.

@joewiz
Copy link
Member

joewiz commented Mar 20, 2023

@adamretter Ok, that'll work.

Copy link
Member

@joewiz joewiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamahito Thanks, this is a great article!

@joewiz joewiz merged commit e8f95f7 into eXist-db:master Mar 20, 2023
@yamahito yamahito deleted the url-rewrite branch March 20, 2023 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[url rewriting.xml] URL Rewrite article needs refactoring
6 participants